#include<stdio.h>

int main(void)
{
     int A[] = {1, 2, 3, 4, 5, 6};
     int B[] = {4, 5, 6, 7, 8, 9, 10, 11, 12};
     int m = sizeof(A) / sizeof(*A);
     int n = sizeof(B) / sizeof(*B);
     int len = m + n;
     int C[len];
     int i = 0, j = 0, k = 0;

     while (i != m && j != n)
     {
          if (A[i] < B[j])
               C[k++] = A[i++];
          else if (A[i] > B[j])
               C[k++] = B[j++];
          else
          {
               C[k++] = A[i++];
               C[k++] = B[j++];
          }
     }
     if(i == m)
     {
          for (int k = j; k < n; k++)
               C[m + k] = B[j++];
     }
     else if(j == n)
     {
          for (int k = i; k < m; k++)
               C[n + k] = A[i++];
     }

     for (int i = 0; i < m + n; i++)
          printf("%d ", C[i]);
     printf("\n");

     return 0;
}
